using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Text;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_Config : Admin, IRequiresSessionState
{
	protected FormView FormView1;
	protected ObjectDataSource ObjectDataSource1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (Fetch.Get("CreatIndex") == "1")
		{
			this.CreatIndexHTML();
		}
		if (!base.admin.CheckAdminPower(0))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Config");
			base.WriteRightErrMsg();
		}
		if (!base.IsPostBack)
		{
			this.GetAppSetings();
		}
		RadioButtonList radioButtonList = (RadioButtonList)this.FormView1.FindControl("RegAnswerCheck");
		radioButtonList.Attributes.Add("onClick", "ShowHide('" + radioButtonList.ClientID + "','RegAnswerdisplay')");
		RadioButtonList radioButtonList2 = (RadioButtonList)this.FormView1.FindControl("RegSendMsg");
		radioButtonList2.Attributes.Add("onClick", "ShowHide('" + radioButtonList2.ClientID + "','div_RegSendMsg')");
		RadioButtonList radioButtonList3 = (RadioButtonList)this.FormView1.FindControl("RegConfirm");
		radioButtonList3.Attributes.Add("onClick", "ShowHide('" + radioButtonList3.ClientID + "','div_RegConfirm')");
		RadioButtonList radioButtonList4 = (RadioButtonList)this.FormView1.FindControl("Wartermark_Type");
		radioButtonList4.Attributes.Add("onClick", "SelectWaterType('" + radioButtonList4.ClientID + "')");
		RadioButtonList radioButtonList5 = (RadioButtonList)this.FormView1.FindControl("VersionType");
		radioButtonList5.Attributes.Add("onClick", "ShowSiteRegKey('" + radioButtonList5.ClientID + "')");
		PlaceHolder placeHolder = (PlaceHolder)this.FormView1.FindControl("ButtonControlField");
	}
	protected void GetAppSetings()
	{
		AppSetings appSetings = new AppSetings();
		TextBox textBox = (TextBox)this.FormView1.FindControl("UC_API");
		TextBox textBox2 = (TextBox)this.FormView1.FindControl("UC_IP");
		TextBox textBox3 = (TextBox)this.FormView1.FindControl("UC_KEY");
		TextBox textBox4 = (TextBox)this.FormView1.FindControl("UC_CHARSET");
		TextBox textBox5 = (TextBox)this.FormView1.FindControl("UC_APPID");
		RadioButtonList radioButtonList = (RadioButtonList)this.FormView1.FindControl("UC_ONorOFF");
		radioButtonList.SelectedValue = appSetings.GetConfig("UC_ONorOFF");
		textBox.Text = appSetings.GetConfig("UC_API");
		textBox2.Text = appSetings.GetConfig("UC_IP");
		textBox3.Text = appSetings.GetConfig("UC_KEY");
		textBox4.Text = appSetings.GetConfig("UC_CHARSET");
		textBox5.Text = appSetings.GetConfig("UC_APPID");
	}
	protected void WriteAppSetings()
	{
		AppSetings appSetings = new AppSetings();
		TextBox textBox = (TextBox)this.FormView1.FindControl("UC_API");
		TextBox textBox2 = (TextBox)this.FormView1.FindControl("UC_IP");
		TextBox textBox3 = (TextBox)this.FormView1.FindControl("UC_KEY");
		TextBox textBox4 = (TextBox)this.FormView1.FindControl("UC_CHARSET");
		TextBox textBox5 = (TextBox)this.FormView1.FindControl("UC_APPID");
		RadioButtonList radioButtonList = (RadioButtonList)this.FormView1.FindControl("UC_ONorOFF");
		appSetings.WriteConfig("UC_ONorOFF", radioButtonList.SelectedValue);
		appSetings.WriteConfig("UC_API", textBox.Text);
		appSetings.WriteConfig("UC_IP", textBox2.Text);
		appSetings.WriteConfig("UC_KEY", textBox3.Text);
		appSetings.WriteConfig("UC_CHARSET", textBox4.Text);
		appSetings.WriteConfig("UC_APPID", textBox5.Text);
	}
	protected void FormView1ItemUpdating(object sender, FormViewUpdateEventArgs e)
	{
		DropDownList dropDownList = (DropDownList)this.FormView1.FindControl("AliPay_Config");
		TextBox textBox = (TextBox)this.FormView1.FindControl("AliPay_Account");
		TextBox textBox2 = (TextBox)this.FormView1.FindControl("AliPay_Key");
		this.WriteAppSetings();
		if (dropDownList.SelectedValue != "system")
		{
			if (string.IsNullOrEmpty(textBox.Text) || string.IsNullOrEmpty(textBox2.Text))
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Config/Alipay"), "");
			}
		}
	}
	protected void FormView1ItemUpdated(object sender, FormViewUpdatedEventArgs e)
	{
		if (e.Exception == null)
		{
			base.WriteLog("Modify", Language.GetAdminMsg("Log/ObjectID", "0"), "SiteConfig");
			TextBox textBox = (TextBox)this.FormView1.FindControl("RegProtocalContent");
			if (RegProtocal.Save(textBox.Text))
			{
				this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "Admin_Config.aspx?id=" + Fetch.Get("id"));
			}
			else
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Common/EditFail", RegProtocal.ErrMsg), "Admin_Config.aspx?id=" + Fetch.Get("id"));
			}
		}
		else
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/EditFail", e.Exception.Message.ToString()), "Admin_Config.aspx?id=" + Fetch.Get("id"));
		}
	}
	protected void FormView1_DataBound(object sender, EventArgs e)
	{
		TextBox textBox = (TextBox)this.FormView1.FindControl("RegProtocalContent");
		textBox.Text = RegProtocal.Get();
	}
	protected void CheckIdentifyRegCodeIsValid_Click(object sender, EventArgs e)
	{
		Literal literal = (Literal)this.FormView1.FindControl("CodeTips");
		TextBox textBox = (TextBox)this.FormView1.FindControl("SiteKey");
		if (Certify.CheckIdentifyRegCode(textBox.Text))
		{
			literal.Text = "<span style='color:red'>序列号正确</span>";
		}
		else
		{
			literal.Text = "<span style='color:red'>序列号不正确</span>";
		}
	}
	protected void CreatIndexHTML(object sender, EventArgs e)
	{
		this.CreatIndexHTML();
	}
	protected void CreatIndexHTML()
	{
		FileIO fileIO = new FileIO();
		string str = "index.html";
		string url = Fetch.webDomain + "/Index.aspx";
		string truePath = fileIO.GetTruePath(this.InstallDir + str);
		Encoding encoding = Encoding.GetEncoding("utf-8");
		string writeWord = null;
		try
		{
			writeWord = fileIO.GetUrlHtml(url, encoding);
		}
		catch (Exception ex)
		{
			this.WriteErrMsg("", ex.Message.ToString(), "");
		}
		try
		{
			fileIO.CreateFile(truePath, writeWord, encoding);
		}
		catch (Exception ex)
		{
			this.WriteErrMsg("", ex.Message.ToString(), "");
		}
		this.WriteSuccessMsg("", Language.GetAdminMsg("CreateHtml/CreateSuccess", this.InstallDir + str), "");
	}
	protected void CreatSmallPic(object sender, EventArgs e)
	{
		this.CreatSmallPic();
	}
	protected void CreatSmallPic()
	{
		try
		{
			StaticFun.UpdateProductImage();
			bool flag = StaticFunApp.CreateSmallImageForAllGoods();
			if (flag)
			{
				this.WriteSuccessMsg("", Language.GetAdminMsg("Common/OperateSuccess"), "Admin_Config.aspx?id=6");
			}
			else
			{
				this.WriteErrMsg("", Language.GetAdminMsg("Common/OperateFail", "文件夹没有写入权限"), "Admin_Config.aspx?id=6");
			}
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[]
			{
				"后台生成缩略图出错"
			});
		}
	}
	protected void CheckSite(object sender, EventArgs e)
	{
		string str = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString();
		base.Response.Redirect(Certify.OfficialCheckUrl + "?sn=" + str);
		base.Response.End();
	}
	protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
	{
	}
}
